#!/usr/bin/python
import re

test_str = '<address>1.2.3.4<address>255.255.248.4'

# result = re.findall('(?:\d{1,3}\.){3}\d{1,3}', test_str)
# l1 = []
# result = re.search()
# for i in result:
#     for x in i:
#         l1.append(x)
# print(l1)

# if result:
#     print(result.group())

# result = re.findall(ip_match, test_str)

# 在长字符串中提取IP地址
ip_match = r"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4]\
    [0-9]|[01]?[0-9][0-9]?)"
# result = re.findall(ip_match, test_str)

# if result:
#     print(result)
# else:
#     print('not re')


# 精确的匹配给定的字符串是否是IP地址
def check_ip(input_address):
    result = re.search(ip_match, input_address)
    if result:
        return True
    else:
        return False


while True:
    input_address = input('请输入IP地址：')
    if input_address.upper() == 'Q':
        break
    print(check_ip(input_address))


# print(check_ip('2.2.2.2'))
# print(check_ip('54.245.126.257'))
